<?php
/*
本系统由苏酷伊基于SiteHub项目二次开发
作者博客： https://www.sukuy.com/
后续更新地址： https://www.sukuy.com/navigation
作者QQ：3288637559
QQ交流群：884250547
任何第三方非官网在发布本系统时，不得删除该注释、版权信息、作者信息及官网等内容
*/
require('../includes/common.php');
require('../includes/lang.class.php');
$title='系统设置';
require('./header.php');
require('./navbar.php');
require('./sidebar.php');
?>
<div class="content-wrapper">
    <section class="content-header"><ol class="breadcrumb">
            <li><a href="./"><?php echo $lang->admin->index; ?></a></li>
            <li class="active"><?php echo $lang->admin->settings; ?></li>
        </ol>
    </section>
    <section class="content">
        <!-- 标签页导航 -->
                <ul class="nav nav-tabs" role="tablist" style="background-color: #f5f5f5; padding: 10px; border-radius: 8px;">
                    <li role="presentation" class="active"><a href="#site-info" aria-controls="site-info" role="tab" data-toggle="tab" class="tab-link" style="border-radius: 8px; margin: 0 5px; padding: 10px 15px;">信息设置</a></li>
                    <li role="presentation"><a href="#image-resources" aria-controls="image-resources" role="tab" data-toggle="tab" class="tab-link" style="border-radius: 8px; margin: 0 5px; padding: 10px 15px;">资源设置</a></li>
                    <li role="presentation"><a href="#account-settings" aria-controls="account-settings" role="tab" data-toggle="tab" class="tab-link" style="border-radius: 8px; margin: 0 5px; padding: 10px 15px;">账号设置</a></li>
                    <li role="presentation"><a href="#email-settings" aria-controls="email-settings" role="tab" data-toggle="tab" class="tab-link" style="border-radius: 8px; margin: 0 5px; padding: 10px 15px;">邮件设置</a></li>
                    <li role="presentation"><a href="#other-info" aria-controls="other-info" role="tab" data-toggle="tab" class="tab-link" style="border-radius: 8px; margin: 0 5px; padding: 10px 15px;">其他设置</a></li>
                    <li role="presentation"><a href="#ad-settings" aria-controls="ad-settings" role="tab" data-toggle="tab" class="tab-link" style="border-radius: 8px; margin: 0 5px; padding: 10px 15px;">广告设置</a></li>
                    <li role="presentation"><a href="#theme-settings" aria-controls="theme-settings" role="tab" data-toggle="tab" class="tab-link" style="border-radius: 8px; margin: 0 5px; padding: 10px 15px;">主题设置</a></li>
                </ul>
                <style>
                    /* 标签页样式覆盖 */
                    .nav-tabs > li.active > a.tab-link,
                    .nav-tabs > li.active > a.tab-link:focus,
                    .nav-tabs > li.active > a.tab-link:hover {
                        color: #3c8dbc !important;
                        background-color: white !important;
                    }
                    .nav-tabs > li > a.tab-link {
                        color: black !important;
                        background-color: white !important;
                    }
                </style>
                <script>
                    // 确保页面加载完成后应用样式
                    $(document).ready(function() {
                        // 强制应用样式
                        $('.nav-tabs > li.active > a.tab-link').css({
                            'color': '#3c8dbc',
                            'background-color': 'white'
                        });
                        $('.nav-tabs > li:not(.active) > a.tab-link').css({
                            'color': 'black',
                            'background-color': 'white'
                        });
                        
                        // 标签页切换时更新样式
                        $('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
                            $('.nav-tabs > li > a.tab-link').css({
                                'color': 'black',
                                'background-color': 'white'
                            });
                            $(e.target).css({
                                'color': '#3c8dbc',
                                'background-color': 'white'
                            });
                        });
                    });
                </script>
                
                <!-- 标签页内容 -->
                <div class="tab-content" style="margin-top: 15px; border-radius: 8px; overflow: hidden;">
                    <!-- 网站信息标签页 -->
                    <div role="tabpanel" class="tab-pane active" id="site-info">
                        <form name="site-info-form" onsubmit="return appSaveSettings('site')" method="post">
                    <!-- 网站名称字段已删除，因为填写后不生效 -->
                    <div class="input-group">
                        <span class="input-group-addon">网站标题</span>
                        <input value="<?php echo $conf['title'];?>" type="text" class="form-control" placeholder="请输入网站标题" name="title">
                    </div>
                    <br />
                    <div class="input-group">
                        <span class="input-group-addon">网站副标题</span>
                        <input value="<?php echo $conf['subtitle'] ? $conf['subtitle'] : '';?>" type="text" class="form-control" placeholder="请输入网站副标题" name="subtitle">
                    </div>
                    <br />
                    <div class="input-group">
                        <span class="input-group-addon">网站关键词</span>
                        <textarea rows="2" class="form-control" placeholder="请输入网站关键词" name="keywords"><?php echo $conf['keywords'];?></textarea>
                    </div>
                    <br />
                    <div class="input-group">
                        <span class="input-group-addon">网站描述</span>
                        <textarea rows="2" class="form-control" placeholder="请输入网站描述" name="description"><?php echo $conf['description'];?></textarea>
                    </div>
                    <br />
                    <div class="input-group">
                        <span class="input-group-addon">网站备案号</span>
                        <input value="<?php echo $conf['icp'];?>" type="text" class="form-control" placeholder="请输入ICP备案号" name="icp">
                    </div>
                    <br />
                    <div class="input-group">
                        <span class="input-group-addon">站长QQ</span>
                        <input value="<?php echo $conf['qq']; ?>" type="number" class="form-control" placeholder="可用于找回管理员密码" name="qq">
                    </div>
                    <br />
                    <div class="input-group">
                        <span class="input-group-addon">联系邮箱</span>
                        <input value="<?php echo $conf['email']; ?>" type="email" class="form-control" placeholder="请输入邮箱" name="email">
                    </div>
                    <br />
                    <div class="input-group">
                        <span class="input-group-addon">建站时间</span>
                        <input value="<?php echo $conf['build_time'];?>" type="date" class="form-control" name="build_time">
                    </div>
                    <br />
                    <div class="input-group">
                        <span class="input-group-addon">缩图接口</span>
                        <input value="<?php echo $conf['shots_api'];?>" type="text" class="form-control" placeholder="请输入缩略图接口" name="shots_api">
                    </div>
                    <br />
                    <div class="input-group">
                        <span class="input-group-addon">TDK接口</span>
                        <input value="<?php echo $conf['tdk_api'];?>" type="text" class="form-control" placeholder="请输入TDK接口" name="tdk_api">
                    </div>
                    <br />
                    <div class="input-group">
                        <span class="input-group-addon">ICO接口</span>
                        <input value="<?php echo $conf['ico_api'];?>" type="text" class="form-control" placeholder="请输入ICO接口" name="ico_api">
                    </div>
                    <br />
                      
                    
                    <input type="submit" class="btn btn-info btn-block" value="修改">
                        </form>
                    </div>
                    
                    <!-- 管理员账号设置标签页 -->
                    <div role="tabpanel" class="tab-pane" id="account-settings">
                        <form name="account-form" onsubmit="return appSaveAccount()" method="post">
                            <div class="input-group">
                                <span class="input-group-addon">管理员账号</span>
                                <input value="<?php echo $conf['admin_user']; ?>" type="text" class="form-control" placeholder="请输入管理员账号" name="admin_user" required>
                            </div>
                            <br />
                            <div class="input-group">
                                <span class="input-group-addon">管理员密码</span>
                                <input type="password" name="admin_pwd" value="" class="form-control" placeholder="请输入当前的管理员密码"/>
                            </div><br/>
                            <div class="input-group">
                                <span class="input-group-addon">新的密码</span>
                                <input type="password" name="newpwd" value="" class="form-control" placeholder="如果不修改密码，请在密码输入框中留空"/>
                            </div><br/>
                            <div class="input-group">
                                <span class="input-group-addon">重输密码</span>
                                <input type="password" name="newpwd2" value="" class="form-control" placeholder="如果不修改密码，请在密码输入框中留空"/>
                            </div><br/>
                            <input type="submit" class="btn btn-info btn-block" name="submit" value="修改">
                        </form>
                    </div>
                    
                    <!-- 其他信息标签页 -->
                    <div role="tabpanel" class="tab-pane" id="other-info">
                        <form name="other-info-form" onsubmit="return appSaveSettings('other')" method="post">
                            <div class="input-group">
                                <span class="input-group-addon">底部信息</span>
                                <textarea rows="3" class="form-control" placeholder="请输入底部信息[支持HTMl代码]" name="info" style="min-width:100%;max-width:100%;"><?php echo $conf['info'];?></textarea>
                            </div><br />
                            <div class="input-group">
                                <span class="input-group-addon">头部脚本代码</span>
                                <textarea rows="3" class="form-control" placeholder="请输入底部脚本代码" name="script_header" style="min-width:100%;max-width:100%;"><?php echo $conf['script_header'];?></textarea>
                            </div><br />
                            <div class="input-group">
                                <span class="input-group-addon">底部脚本代码</span>
                                <textarea rows="3" class="form-control" placeholder="请输入底部脚本代码" name="script_footer" style="min-width:100%;max-width:100%;"><?php echo $conf['script_footer'];?></textarea>
                            </div>
                            <br />
                            <input type="submit" class="btn btn-info btn-block" value="修改">
                        </form>
                    </div>
                    
                    <!-- 邮件设置标签页 -->
                    <div role="tabpanel" class="tab-pane" id="email-settings">
                        <form name="email-settings-form" onsubmit="return appSaveSettings('email')" method="post">
                            <div class="input-group">
                                <span class="input-group-addon">SMTP服务器</span>
                                <input value="<?php echo $conf['smtp_server']; ?>" type="text" class="form-control" placeholder="例如: smtp.qq.com" name="smtp_server">
                            </div>
                            <br />
                            <div class="input-group">
                                <span class="input-group-addon">SMTP端口</span>
                                <input value="<?php echo $conf['smtp_port']; ?>" type="number" class="form-control" placeholder="例如: 465" name="smtp_port">
                            </div>
                            <br />
                            <div class="input-group">
                                <span class="input-group-addon">发件人邮箱</span>
                                <input value="<?php echo $conf['smtp_from']; ?>" type="email" class="form-control" placeholder="请输入发件人邮箱" name="smtp_from">
                            </div>
                            <br />
                            <div class="input-group">
                                <span class="input-group-addon">SMTP用户名</span>
                                <input value="<?php echo $conf['smtp_user']; ?>" type="text" class="form-control" placeholder="通常与发件人邮箱相同" name="smtp_user">
                            </div>
                            <br />
                            <div class="input-group">
                                <span class="input-group-addon">SMTP密码</span>
                                <input value="<?php echo $conf['smtp_pass']; ?>" type="password" class="form-control" placeholder="请输入SMTP密码或授权码" name="smtp_pass">
                            </div>
                            <br />
                            <div class="input-group">
                                <span class="input-group-addon">使用SSL/TLS</span>
                                <select class="form-control" name="smtp_ssl">
                                    <option value="1"<?php echo $conf['smtp_ssl'] == 1 ? ' selected' : ''; ?>>是</option>
                                    <option value="0"<?php echo $conf['smtp_ssl'] == 0 ? ' selected' : ''; ?>>否</option>
                                </select>
                            </div>
                            <br />
                            <div class="input-group">
                                <span class="input-group-addon">管理员收信邮箱</span>
                                <input value="<?php echo $conf['admin_email']; ?>" type="email" class="form-control" placeholder="用于接收网站审核通知" name="admin_email">
                            </div>
                            <br />
                            <div class="input-group">
                                <span class="input-group-addon">发件人名称</span>
                                <input value="<?php echo $conf['smtp_name']; ?>" type="text" class="form-control" placeholder="显示的发件人名称" name="smtp_name">
                            </div>
                            <br />
                             <div class="input-group">
                                <span class="input-group-addon">测试收信邮箱</span>
                                <input type="email" class="form-control" placeholder="用于测试SMTP发信是否正常" name="test_email">
                            </div>
                            <br />
                            <div class="form-group">
                                <button type="button" class="btn btn-info" onclick="testEmailSettings()">测试发信</button>
                                <p class="text-muted" id="email-test-result" style="margin-top: 10px;"></p>
                            </div>
                            <input type="submit" class="btn btn-info btn-block" value="保存设置">
                        </form>
                    </div>
                    
                    <!-- 图片资源设置标签页 -->
                    <div role="tabpanel" class="tab-pane" id="image-resources">
                        
                        <!-- 主LOGO上传 -->
                                <div class="input-group">
                                    <span class="input-group-addon">主LOGO</span>
                                    <input type="file" name="logo_upload" class="form-control" accept="image/*">
                                    <span class="input-group-btn">
                                        <button onclick="uploadImage('logo_upload', '/assets/images/logo.png');" class="btn btn-info">上传</button>
                                    </span>
                                </div>
                                <p class="text-muted"><img src="../assets/images/logo.png" style="height:24px;"></p>
                                <br />
                                
                                <!-- 辅LOGO上传 -->
                                <div class="input-group">
                                    <span class="input-group-addon">辅LOGO</span>
                                    <input type="file" name="logo_fixed_upload" class="form-control" accept="image/*">
                                    <span class="input-group-btn">
                                        <button onclick="uploadImage('logo_fixed_upload', '/assets/images/logo_fixed.png');" class="btn btn-info">上传</button>
                                    </span>
                                </div>
                                <p class="text-muted"><img src="../assets/images/logo_fixed.png" style="height:24px;"></p>
                                <br />
                                <!-- Favicon图标上传 -->
                                <div class="input-group">
                                    <span class="input-group-addon">Favicon图标</span>
                                    <input type="file" name="favicon_upload" class="form-control" accept="image/x-icon,image/png">
                                    <span class="input-group-btn">
                                        <button onclick="uploadImage('favicon_upload', '/favicon.ico');" class="btn btn-info">上传</button>
                                    </span>
                                </div>
                                <p class="text-muted"><img src="../favicon.ico" style="height:24px;"></p>
                                <br />
                                
                                <!-- 站点默认ICO图标上传 -->
                                <div class="input-group">
                                    <span class="input-group-addon">默认ICO图标</span>
                                    <input type="file" name="default_ico_upload" class="form-control" accept="image/x-icon,image/png">
                                    <span class="input-group-btn">
                                        <button onclick="uploadImage('default_ico_upload', '/assets/images/default_ico.png');" class="btn btn-info">上传</button>
                                    </span>
                                </div>
                                <p class="text-muted"><img src="../assets/images/default_ico.png" style="height:24px;"></p>
                                <br />
            
                                <!-- loading加载图上传 -->
                                <div class="input-group">
                                    <span class="input-group-addon">loading加载图</span>
                                    <input type="file" name="loading_upload" class="form-control" accept="image/gif,image/png">
                                    <span class="input-group-btn">
                                        <button onclick="uploadImage('loading_upload', '/assets/images/loading.gif');" class="btn btn-info">上传</button>
                                    </span>
                                </div>
                                <p class="text-muted"><img src="../assets/images/loading.gif" style="height:24px;"></p>
                                <br />
                                  
                                <!-- 微信二维码上传 -->
                                <div class="input-group">
                                    <span class="input-group-addon">微信二维码</span>
                                    <input type="file" name="weixin_upload" class="form-control" accept="image/*">
                                    <span class="input-group-btn">
                                        <button onclick="uploadImage('weixin_upload', '/assets/images/weixin.png');" class="btn btn-info">上传</button>
                                    </span>
                                </div>
                                <p class="text-muted"><img src="../assets/images/weixin.png" style="height:100px;"></p>
                                <br />
                                
                                <!-- 顶栏背景图上传 -->
                                <div class="input-group">
                                    <span class="input-group-addon">首页背景图</span>
                                    <input type="file" name="banner_upload" class="form-control" accept="image/*">
                                    <span class="input-group-btn">
                                        <button onclick="uploadImage('banner_upload', '/assets/images/banner.jpg');" class="btn btn-info">上传</button>
                                    </span>
                                </div>
                                <p class="text-muted"><img src="../assets/images/banner.jpg" style="max-height:100px;max-width:300px;"></p>
                                <br />
                                 
                                <!-- 登录背景图上传 -->
                                <div class="input-group">
                                    <span class="input-group-addon">登录背景图</span>
                                    <input type="file" name="login_bg_upload" class="form-control" accept="image/*">
                                    <span class="input-group-btn">
                                        <button onclick="uploadImage('login_bg_upload', '/assets/images/login_bg.jpg');" class="btn btn-info">上传</button>
                                    </span>
                                </div>
                                <p class="text-muted"><img src="../assets/images/login_bg.jpg" style="max-height:100px;max-width:300px;" onerror="this.src='../assets/images/banner.jpg';"></p>
                                <br />
                    </div>

                    <!-- 广告设置标签页 -->
                    <div role="tabpanel" class="tab-pane" id="ad-settings">
                        <form name="ad-settings-form" onsubmit="return appSaveSettings('ad')" method="post">
                            <div class="input-group">
                                <span class="input-group-addon">侧边栏广告显示</span>
                                <select class="form-control" name="sidebar_ad_show">
                                    <option value="1"<?php echo isset($conf['sidebar_ad_show']) && $conf['sidebar_ad_show'] == 1 ? ' selected' : ''; ?>>显示</option>
                                    <option value="0"<?php echo !isset($conf['sidebar_ad_show']) || $conf['sidebar_ad_show'] == 0 ? ' selected' : ''; ?>>隐藏</option>
                                </select>
                            </div>
                            <br />
                            <div class="input-group">
                                <span class="input-group-addon">侧边栏广告图片</span>
                                <input type="file" name="sidebar_ad_image" class="form-control" accept="image/*">
                                <span class="input-group-btn">
                                    <button onclick="uploadImage('sidebar_ad_image', '/assets/images/sidebar_ad.png')" class="btn btn-info">上传</button>
                                </span>
                            </div>
                            <p class="text-muted"><img src="../assets/images/sidebar_ad.png" style="max-height:100px;max-width:300px;"></p>
                            <br />
                            <div class="input-group">
                                <span class="input-group-addon">侧边栏广告链接</span>
                                <input value="<?php echo isset($conf['sidebar_ad_url']) ? $conf['sidebar_ad_url'] : 'https://www.sukuy.com/'; ?>" type="text" class="form-control" placeholder="请输入广告链接" name="sidebar_ad_url">
                            </div>
                            <br />
                            <div class="input-group">
                                <span class="input-group-addon">广告描述</span>
                                <input value="<?php echo isset($conf['sidebar_ad_desc']) ? $conf['sidebar_ad_desc'] : ''; ?>" type="text" class="form-control" placeholder="请输入广告描述" name="sidebar_ad_desc">
                            </div>
                            <br />
                            <input type="submit" class="btn btn-info btn-block" value="保存设置">
                        </form>
                    </div>
                    
                    <!-- 主题设置标签页 -->
                    <div role="tabpanel" class="tab-pane" id="theme-settings">
                        <form name="theme-settings-form" onsubmit="return appSaveSettings('theme')" method="post">
                            <div class="input-group">
                                <span class="input-group-addon">前端主题</span>
                                <select class="form-control" name="theme">
                                    <option value="default"<?php echo isset($conf['theme']) && $conf['theme'] == 'default' ? ' selected' : ''; ?>>default</option>
                                    <option value="mfc_theme"<?php echo isset($conf['theme']) && $conf['theme'] == 'mfc_theme' ? ' selected' : ''; ?>>MF创业主题</option>
                                </select>
                            </div>
                            <br />
                            <div class="input-group">
                                <span class="input-group-addon">主题主色调</span>
                                <input value="<?php echo isset($conf['theme_color']) ? $conf['theme_color'] : '#3e92cc'; ?>" type="text" class="form-control" placeholder="请输入主题主色调，如 #3e92cc" name="theme_color">
                            </div>
                            <br />
                            <div class="input-group">
                                <span class="input-group-addon">主题背景色</span>
                                <input value="<?php echo isset($conf['theme_bgcolor']) ? $conf['theme_bgcolor'] : '#f5f5f5'; ?>" type="text" class="form-control" placeholder="请输入主题背景色，如 #f5f5f5" name="theme_bgcolor">
                            </div>
                            <br />
                            <input type="submit" class="btn btn-info btn-block" value="保存设置">
                        </form>
                    </div>
                </div>
    </section>
</div>

<?php require('./footer.php'); ?>
<script>
    function appSaveSettings(type) {
        var ii = showLoading();
        var formData;
        
        if (type === 'site') {
            formData = $('[name="site-info-form"]').serialize();
        } else if (type === 'email') {
            formData = $('[name="email-settings-form"]').serialize();
        } else if (type === 'ad') {
            formData = $('[name="ad-settings-form"]').serialize();
        } else if (type === 'theme') {
            formData = $('[name="theme-settings-form"]').serialize();
        } else {
            formData = $('[name="other-info-form"]').serialize();
        }
        
        $.ajax({
            type: 'POST',
            url: 'ajax.php?act=settings',
            data: formData,
            dataType: 'json',
            success: function(data) {
                closeLayer(ii);
                if (data.code == 0) {
                    showSuccess(data.msg || '保存成功！', function() {
                        window.location.assign(window.location.href);
                    });
                } else {
                    showAlert(data.msg || '保存失败！', '提示', 2);
                }
            },
            error: function(data) {
                closeLayer(ii);
                showAlert(data.msg || '服务器错误', '提示', 2);
            }
        });
        return false;
    }
    
    // 保存管理员账号设置
    function appSaveAccount() {
        var ii = showLoading();
        var formData = $('[name="account-form"]').serialize();
        
        $.ajax({
            type: 'POST',
            url: 'ajax.php?act=account',
            data: formData,
            dataType: 'json',
            success: function(data) {
                closeLayer(ii);
                if (data.code == 0) {
                    showSuccess(data.msg || '保存成功！', function() {
                        window.location.assign(window.location.href);
                    });
                } else {
                    showAlert(data.msg || '保存失败！', '提示', 2);
                }
            },
            error: function(data) {
                closeLayer(ii);
                showAlert(data.msg || '服务器错误', '提示', 2);
            }
        });
        return false;
    }
    
    // 测试发信函数 - 增强版
    function testEmailSettings() {
    // 强制要求填写测试邮箱
    var testEmail = $('input[name="test_email"]').val();
    if (!testEmail) {
        showAlert('请填写测试邮箱账号', '提示', 2);
        setTimeout(function() {
            $('input[name="test_email"]').focus();
        }, 300);
        return;
    }
    
    // 使用统一的加载弹窗
    var ii = showLoading('正在连接邮件服务器', '请稍候，正在发送测试邮件...');
    
    var formData = $('[name="email-settings-form"]').serialize();
    var resultElement = $('#email-test-result');
    
    // 清空之前的测试结果
    resultElement.empty();
    
    $.ajax({
        type: 'POST',
        url: 'email.php?act=test_email',
        data: formData,
        dataType: 'json',
        timeout: 60000,  // 设置60秒超时
        beforeSend: function() {
            // 添加发送前的友好提示
            resultElement.html('<div class="text-info p-2 bg-info bg-opacity-10 rounded"><i class="fa fa-spinner fa-spin mr-2"></i>正在准备发送测试邮件...</div>');
        },
        success: function(data) {
            closeLayer(ii);
            
            // 清空之前的测试结果
            resultElement.empty();
            
            if (data.code == 0) {
                // 测试成功 - 使用统一的成功弹窗
                showSuccess('测试成功！', function() {
                    // 同时在页面上也显示成功信息
                    resultElement.html('<div class="text-success p-3 bg-success bg-opacity-15 rounded-lg border border-success border-opacity-20 shadow-sm"><i class="fa fa-check-circle mr-2 text-success"></i><strong>✓ 测试成功！</strong>邮件已发送至 ' + $('input[name="test_email"]').val() + '</div><div class="text-sm text-gray-600 mt-2">提示：请检查垃圾邮件文件夹，如遇问题可尝试调整SSL/TLS设置或端口。</div>');
                });
            } else {
                // 测试失败 - 使用统一的错误弹窗
                var errorMsg = (data.msg || '未知错误').replace(/\n/g, '<br>');
                showAlert('测试失败！\n' + errorMsg.replace(/<br>/g, '\n'), '提示', 2);
                
                // 同时在页面上也显示错误信息
                resultElement.html('<div class="text-danger p-3 bg-danger bg-opacity-15 rounded-lg border border-danger border-opacity-20 shadow-sm"><i class="fa fa-exclamation-circle mr-2 text-danger"></i><strong>✗ 测试失败：</strong>' + errorMsg + '</div><div class="text-sm text-gray-600 mt-2">提示：请仔细检查SMTP服务器配置，并确保服务器允许外部连接。</div>');
            }
        },
        error: function(xhr, status, error) {
            closeLayer(ii);
            
            // 清空之前的测试结果
            resultElement.empty();
            
            // 尝试获取更详细的错误信息
            var errorMsg = '未知错误';
            
            if (status === 'timeout') {
                errorMsg = '连接超时\n邮件服务器响应超时\n提示：请检查网络连接和服务器状态，或尝试更换端口';
            } else if (xhr.responseText) {
                try {
                    // 尝试解析响应文本作为JSON
                    var responseData = JSON.parse(xhr.responseText);
                    if (responseData.msg) {
                        errorMsg = responseData.msg;
                    }
                } catch (e) {
                    // 如果不是JSON，显示原始响应文本的前300个字符，提供更多上下文
                    var errorText = xhr.responseText.substring(0, 300);
                    // 清理可能的HTML标签
                    errorText = errorText.replace(/<[^>]*>/g, '');
                    errorMsg = (error || status || '服务器错误') + '\n' + errorText + (xhr.responseText.length > 300 ? '...' : '') + '\n提示：无法解析服务器响应，请检查邮件配置或联系管理员。';
                    
                    // 同时在页面上也显示错误信息
                    resultElement.html('<div class="text-danger p-2 bg-danger bg-opacity-10 rounded"><i class="fa fa-exclamation-circle mr-2"></i>✗ 请求失败：' + (error || status || '服务器错误') + '</div><div class="text-sm text-gray-500 mt-1">' + errorText + (xhr.responseText.length > 300 ? '...' : '') + '</div><div class="text-sm text-gray-600 mt-2">提示：无法解析服务器响应，请检查邮件配置或联系管理员。</div>');
                }
            } else if (error) {
                errorMsg = error;
            } else if (status) {
                errorMsg = status;
            }
            
            // 请求错误 - 使用统一的错误弹窗
            showAlert('请求失败！\n' + errorMsg, '提示', 2);
            
            // 如果还没有设置页面上的错误信息，则设置
            if (resultElement.html() === '') {
                resultElement.html('<div class="text-danger p-2 bg-danger bg-opacity-10 rounded"><i class="fa fa-exclamation-circle mr-2"></i>✗ 请求失败：' + errorMsg.split('\n')[0] + '</div>');
            }
        }
    });
}

// 保存设置的通用函数
function appSaveSettings(type) {
    var ii = showLoading();
    var formData;
    
    if (type === 'site') {
        formData = $('[name="site-info-form"]').serialize();
    } else if (type === 'email') {
        formData = $('[name="email-settings-form"]').serialize();
    } else if (type === 'ad') {
        formData = $('[name="ad-settings-form"]').serialize();
    } else if (type === 'theme') {
        formData = $('[name="theme-settings-form"]').serialize();
    } else {
        formData = $('[name="other-info-form"]').serialize();
    }
    
    $.ajax({
        type: 'POST',
        url: 'ajax.php?act=settings',
        data: formData,
        dataType: 'json',
        success: function(data) {
            closeLayer(ii);
            if (data.code == 0) {
                showSuccess(data.msg || '保存成功！', function() {
                    window.location.assign(window.location.href);
                });
            } else {
                showAlert(data.msg || '保存失败！', '提示', 2);
            }
        },
        error: function(data) {
            closeLayer(ii);
            showAlert(data.msg || '服务器错误', '提示', 2);
        }
    });
    return false;
}
</script>
</body>
</html>